<template>
    <div>
        <div class="filter-container">
            <el-form label-position="top" :inline="true" label-width="80px">
                <el-row>
                    <el-form-item label="玩家ID">
                        <el-input class="filter-item" type="textarea" autosize v-model="search.playerId" placeholder="请输入玩家ID"></el-input>
                    </el-form-item>
                    <el-form-item label="用户ID">
                        <el-input class="filter-item" type="textarea" autosize v-model="search.userId" placeholder="请输入用户ID"></el-input>
                    </el-form-item>
                    <el-form-item label="昵称">
                        <el-input class="filter-item" clearable v-model="search.nickname" placeholder="模糊搜索" @keyup.enter.native="pageNo = 1;handleSearch()"></el-input>
                    </el-form-item>
                    <el-form-item label="手机">
                        <el-input class="filter-item" clearable v-model="search.mobile" placeholder="" @keyup.enter.native="pageNo = 1;handleSearch()"></el-input>
                    </el-form-item>

                    <el-form-item label="注册IP">
                        <el-input class="filter-item" clearable v-model="search.register_ip" placeholder="" @keyup.enter.native="pageNo = 1;handleSearch()"></el-input>
                    </el-form-item>

                    <el-form-item label="设备标识">
                        <el-input clearable v-model="search.searchValue" placeholder="" @keyup.enter.native="pageNo = 1;handleSearch()">
                            <el-select v-model="search.searchField" slot="prepend" style="width: 100px">
                                <el-option label="注册UUID" value="registerUuid"></el-option>
                                <el-option label="登录UUID" value="uuid"></el-option>
                                <el-option label="IMEI" value="imei"></el-option>
                                <el-option label="OAID" value="oaid"></el-option>
                                <el-option label="IDFA" value="idfa"></el-option>
                            </el-select>
                        </el-input>
                    </el-form-item>
                </el-row>

                <el-row>
                    <el-form-item label="所属渠道">
                        <select-app-source v-model="search.source" multiple></select-app-source>
                    </el-form-item>
                    <el-form-item label="在线">
                        <el-select v-model="search.online" clearable class="filter-item" placeholder="在线" style="width: 100px;">
                            <el-option :label="item.label" :value="item.value" v-for="(item, index) in options.online" :key="index"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="标签">
                        <el-select class="filter-item" v-model="search.flagBit" multiple collapse-tags placeholder="请选择" style="width: 140px;">
                            <el-option
                                v-for="item in options.flagBit"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="注册时间">
                        <picker-datetime-range v-model="search.created_at"></picker-datetime-range>
                    </el-form-item>
                    <el-form-item label="-">
                        <el-button icon="el-icon-search" type="primary" :loading="loading" @click="pageNo = 1;handleSearch()">搜索</el-button>
                        <el-button @click="exportExcel" v-if="$ENABLE_EXPORT">导出本页</el-button>
                    </el-form-item>
                </el-row>
            </el-form>
        </div>

        <vxe-table
            :loading="loading"
            ref="xTable"
            highlight-hover-row
            style="width: 100%"
            class="text-center"
            :export-config="{ filename: '用户信息' }"
            :row-class-name="tableRowClassName"
            @checkbox-all="selectAllEvent"
            @checkbox-change="selectChangeEvent"
            :max-height="maxHeight">
            <vxe-table-column type="checkbox" width="40" fixed="left"/>
            <vxe-table-column title="用户ID" field="userId" min-width="80" fixed="left"/>
            <vxe-table-column title="玩家ID" field="playerId" min-width="80" fixed="left"/>
            <vxe-table-column title="昵称" field="nickname" min-width="120"/>
            <vxe-table-column title="用户账号" field="username" min-width="120"/>
<!--            <vxe-table-column title="头像" field="avatar" width="60">-->
<!--                <template slot-scope="scope"><el-avatar icon="el-icon-user-solid" :src="scope.row.avatar" :size="30" shape="square" fit="cover" v-if="scope.row.avatar.length > 10"></el-avatar></template>-->
<!--            </vxe-table-column>-->
            <vxe-table-column title="渠道" field="source" min-width="130" formatter="formatAppSourceName"/>
            <vxe-table-column title="登录渠道" field="target_source" min-width="130" formatter="formatAppSourceName"/>
            <vxe-table-column title="设备码" field="uuid" min-width="150"/>
            <vxe-table-column title="注册IP" field="register_ip" width="110"/>
            <vxe-table-column title="注册IP归属" field="register_ip_region" width="110"/>
            <vxe-table-column title="最后IP" field="ip" width="110"/>
<!--            <vxe-table-column title"IDFA" field="idfa" />-->
            <vxe-table-column title="手机" field="mobile" min-width="100"/>
            <vxe-table-column title="OS" field="os" min-width="100"/>
            <vxe-table-column title="机型" field="device" min-width="100"/>
            <vxe-table-column title="热更版本" field="version" min-width="70"/>
            <vxe-table-column title="APK版本" field="app_version" min-width="70"/>
            <vxe-table-column title="今日充值" field="pay_sum_today" min-width="70" formatter="formatHumanRmb"/>
            <vxe-table-column title="累计充值" field="account_profit.sum_pay" min-width="70" formatter="formatHumanRmb"/>
<!--            <vxe-table-column title"在线" field="status" />-->
            <vxe-table-column title="实名" field="realname" type="html" min-width="80">
                <template #default="{row}">
                    <a
                        v-if="row.realname"
                        :href="$router.resolve({name: 'user.realname', query:{playerId: row.playerId}}).href"
                        title="点击跳转">
                        {{ options.realNameStatus[row.realname] }}
                    </a>

                </template>
            </vxe-table-column>
            <vxe-table-column title="标签" field="flagBit" :show-overflow="false" min-width="120" type="html">
                <template #default="{row}">
                    <span v-if="row.flagBit" class="color-danger">{{ formatUserFlag(row.flagBit) || '...' }}</span>
                    <span v-else>-</span>
                </template>
            </vxe-table-column>
            <vxe-table-column title="最后登录" field="login_at" width="140"/>
            <vxe-table-column title="注册时间" field="created_at" width="140"/>
            <vxe-table-column title="行为" width="80" fixed="right" :visible="!$ENABLE_CUSTOMER">
                <template #default="{row}">
                    <a @click="showDialogBehaviorLogs(row.playerId)" title="点击查看">查看</a>
                </template>
            </vxe-table-column>
            <vxe-table-column title="操作日志" field="operate_logs" :show-overflow="false" width="80" fixed="right">
                <template #default="{row}">
                    <a v-if="row.operate_logs_count" @click="showDialogOperateLogs(row.userId)" title="点击查看">查看</a>
                    <span v-else>-</span>
                </template>
            </vxe-table-column>
            <vxe-table-column title="拉黑" width="80" fixed="right">
                <template #default="{row}">
                    <template v-if="row.playerId">
                        <el-popover
                            v-if="row.blacklist"
                            placement="left"
                            width="400"
                            trigger="hover">
                            <vxe-table :data="[row.blacklist]">
                                <vxe-table-column field="created_at" title="操作时间" width="140"/>
                                <vxe-table-column field="manager_name" title="操作人" width="100"/>
                                <vxe-table-column field="remark" title="备注"/>
                            </vxe-table>
                            <a slot="reference" title="点击查看">查看</a>
                        </el-popover>
                        <a v-else @click="showDialogBlackList(row.playerId)" title="点击查看" class="color-danger">拉黑</a>
                    </template>
                </template>
            </vxe-table-column>
            <vxe-table-column title="操 作" width="230" :show-overflow="false" fixed="right">
                <template #default="{row, rowIndex}">
                    <el-button
                        type="primary"
                        @click="edit(row)">
                        编辑
                    </el-button>
                    <el-dropdown @command="flagChange" split-button type="primary">
                        <span class="el-dropdown-link">
                            <i class="el-icon-loading" v-if="row.loading"></i>
                            <span v-else>标记</span>
                        </span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item :command="{index: row.playerId, flag: 1}">
                                {{ (row.flagBit & 1) === 1 ? '解锁' : '锁定' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 2}">
                                {{ (row.flagBit & 2) === 2 ? '取消内部号' : '设为内部号' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 4}">
                                {{ (row.flagBit & 4) === 4 ? '取消羊毛党' : '设为羊毛党' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 8}">
                                {{ (row.flagBit & 8) === 8 ? '取消小号' : '设为小号' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 16}">
                                {{ (row.flagBit & 16) === 16 ? '取消关注' : '设为关注' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 32}">
                                {{ (row.flagBit & 32) === 32 ? '取消投诉' : '设为投诉' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 64}">
                                {{ (row.flagBit & 64) === 64 ? '取消注销' : '设为注销' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 128}">
                                {{ (row.flagBit & 128) === 128 ? '取消审核' : '设为审核' }}
                            </el-dropdown-item>
                            <el-dropdown-item :command="{index: row.playerId, flag: 256}">
                                {{ (row.flagBit & 256) === 256 ? '取消危险' : '设为危险' }}
                            </el-dropdown-item>
<!--                            <el-dropdown-item :command="{delete: true, row: scope.row}">-->
<!--                                删除-->
<!--                            </el-dropdown-item>-->
                        </el-dropdown-menu>
                    </el-dropdown>
                    <el-button
                        type="primary"
                        @click="detail(row)">
                        详情
                    </el-button>
                </template>
            </vxe-table-column>
        </vxe-table>

        <div class="mt-10 pull-left">
            <clipboard-column :data="selected" :column-infos="columnInfos" :field-filter="['playerId', 'userId', 'username', 'mobile', 'uuid', 'register_ip', 'ip']" title="复制玩家属性"></clipboard-column>

            <el-dropdown @command="flagChangeArr" split-button type="primary">
                <span class="el-dropdown-link" ref="echarType">设置标记</span>
                <el-dropdown-menu slot="dropdown" >
                    <el-dropdown-item :command="{index:'set', flag: 1}">锁定</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 2}">设为内部号</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 4}">设为羊毛党</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 8}">设为小号</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 16}">设为关注</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 32}">设为投诉</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 64}">设为注销</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 128}">设为审核</el-dropdown-item>
                    <el-dropdown-item :command="{index:'set', flag: 256}">设为危险</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
            <el-dropdown @command="flagChangeArr" split-button type="primary">
          <span class="el-dropdown-link" ref="echarType1">
           取消标记
          </span>
                <el-dropdown-menu slot="dropdown" >
                    <el-dropdown-item :command="{index:'cancel', flag: 1}">取消锁定</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 2}">取消内部号</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 4}">取消羊毛党</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 8}">取消小号</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 16}">取消关注</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 32}">取消投诉</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 64}">取消注销</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 128}">取消审核</el-dropdown-item>
                    <el-dropdown-item :command="{index:'cancel', flag: 256}">取消危险</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>

            <el-button icon="el-icon-mouse" @click="updateSourceOpen">修改渠道</el-button>
<!--            <el-dropdown @command="dialogUpdateSource.show = true" split-button type="default">-->
<!--                <span class="el-dropdown-link" ref="echarType2">修改渠道</span>-->
<!--                <el-dropdown-menu slot="dropdown" >-->
<!--                    <el-dropdown-item :command="{source: item.id}" v-for="(item, index) in appSourceAll" :key="index">{{ item.name }}</el-dropdown-item>-->
<!--                </el-dropdown-menu>-->
<!--            </el-dropdown>-->
        </div>

        <el-pagination
            class="pull-right"
            background
            :current-page.sync="pageNo"
            :page-sizes="pageOptions.pageSizesList"
            :page-size="pageSize"
            :layout="pageOptions.layout"
            :total="totalDataNumber"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange">
        </el-pagination>

        <el-dialog
            :title="form.data && form.data.userId ? '编辑' : '添加'"
            :visible.sync="form.show"
            width="50%"
            :append-to-body="true"
            :close-on-click-modal="false"
            center>
            <dialog-form
                :data="form.data"
                v-on:submit="onFormSubmit"
                v-on:cancel="form.show = false">
            </dialog-form>
        </el-dialog>

        <el-dialog title="操作日志" :visible.sync="dialogOperateLog.show" width="70%">
            <dialog-operate-logs
                v-if="dialogOperateLog.show"
                :user-id="dialogOperateLog.userId"
                @submit="dialogOperateLog.show = false"
                @cancel="dialogOperateLog.show = false">
            </dialog-operate-logs>
        </el-dialog>

        <el-dialog title="行为日志" :visible.sync="dialogBehaviorLog.show" width="80%">
            <dialog-behavior-logs
                v-if="dialogBehaviorLog.show"
                :player-id="dialogBehaviorLog.playerId"
                @submit="dialogBehaviorLog.show = false"
                @cancel="dialogBehaviorLog.show = false">
            </dialog-behavior-logs>
        </el-dialog>

        <el-dialog title="修改渠道" :visible.sync="dialogUpdateSource.show" width="500px">
            <el-form label-position="top">
                <el-form-item label="目标渠道">
                    <select-app-source v-model="dialogUpdateSource.source"></select-app-source>
                </el-form-item>
                <el-form-item label="操作备注">
                    <el-input type="textarea" :autosize="{minRows: 5}" v-model="dialogUpdateSource.remark" placeholder="备注一下吧"></el-input>
                </el-form-item>
                <el-form-item label="数据">
                    已选: {{ selected.length }} 条, 成功: {{ dialogUpdateSource.success }} 条
                </el-form-item>
                <el-form-item label="">
                    <el-button type="primary" :loading="loading" @click="updateSourceSubmit">确定</el-button>
                    <el-button @click="dialogUpdateSource.show = false">返回</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog
            :append-to-body="true"
            :close-on-click-modal="false"
            title="加入黑名单"
            :visible.sync="dialogBlackList.show"
            width="500px">
            <dialog-add-blacklist :player-id="dialogBlackList.playerId" @submit="dialogBlackList.show = false; handleSearch();" @cancel="dialogBlackList.show = false;"/>
        </el-dialog>

        <el-dialog title="详情" :visible.sync="detailForm.show" width="40%" center>
            <detail-form
                v-if="detailForm.show"
                :player-id="detailForm.playerId"
                :data="detailForm.data"
                @submit="detailForm.show = false"
                @cancel="detailForm.show = false">
            </detail-form>
        </el-dialog>
    </div>
</template>

<script>
import dialogForm from './form'
import DialogOperateLogs from './operate-logs';
import ClipboardColumn from "~/components/Dialog/clipboard-column";
import DialogBehaviorLogs from "~/views/operation/behavior-log";
import DialogAddBlacklist from "~/views/user/dialog-add-blacklist";
import DetailForm from "./detail";

export default {
    components: {
        dialogForm,
        DialogOperateLogs,
        ClipboardColumn,
        DialogBehaviorLogs,
        DialogAddBlacklist,
        DetailForm,
    },
    props: {
        field:{
            userId:'',
            status:'',
        }
    },
    data() {
        return {
            search: {
                userId: '',
                playerId: '',
                username: '',
                nickname: '',
                mobile: '',
                register_ip: '',
                online: '',
                flagBit: '',
                created_at: [],
                searchField: 'uuid',
                searchValue: '',
            },

            loading: false,
            selected: [],
            tableData: [],
            pageNo: 1,
            pageSize: 20,
            totalDataNumber: 0,
            pageOptions: this.$store.state.backend.pageOptions,
            options: this.$store.state.user.options,
            form: {
                data: {},
                show: false,
            },
            dialogOperateLog: {
                show: false,
                userId: '',
            },
            dialogBehaviorLog: {
                show: false,
                playerId: '',
            },
            dialogUpdateSource: {
                show: false,
                source: '',
                remark: '',
                success: 0,
            },
            dialogBlackList: {
                show: false,
                playerId: '',
            },
            detailForm: {
                show: false,
                data: {},
            },
            columnInfos: [],
        }
    },
    computed: {
        maxHeight() {
            return this.$store.state.backend.windowInnerHeight - 340;
        },
        appSourceAll() {
            return this.$store.state.appSource.all;
        }
    },
    methods: {
        selectAllEvent ({ checked, records }) {
            this.selected = records;
            // console.log(checked ? '所有勾选事件' : '所有取消事件', records)
        },
        selectChangeEvent ({ checked, records }) {
            this.selected = records;
            // console.log(checked ? '勾选事件' : '取消事件', records)
        },
        handleSizeChange(val) {
            this.pageNo = 1;
            this.pageSize = parseInt(`${val}`);
            this.handleSearch();
        },
        handleCurrentChange(val) {
            this.pageNo = parseInt(`${val}`);
            this.handleSearch();
        },
        handleSearch() {
            this.loading = true;
            this.selected = [];
            let filter = Object.assign({}, this.search, {
                page: this.pageNo,
                pageSize: this.pageSize,
            });
            if (filter.searchField && filter.searchValue) {
                filter[filter.searchField] = filter.searchValue;
            }
            // 简单去重
            if (filter.userId) {
                filter.userId = Array.from(new Set(
                    filter.userId.split('\n').filter(v=>v).filter(v => !isNaN(Number(v)))
                ));
            }
            if (filter.playerId) {
                filter.playerId = Array.from(new Set(
                    filter.playerId.split('\n').filter(v=>v).filter(v => !isNaN(Number(v)))
                ));
            }
            this.$store.dispatch('user/Lists', filter).then(({data}) => {
                let list = data.data.map(v => {
                    v.loading = false;
                    return v;
                });
                // 追加loading
                this.$refs.xTable.reloadData(list);
                this.totalDataNumber = data.meta.total;
            }).finally(() => {
                this.loading = false;
            });
        },
        tableRowClassName({row, rowIndex}) {
            if (row.online) return 'color-success';
            return '';
        },
        initData() {
            this.handleSearch();
        },
        edit(row) {
            this.form.data = row;
            this.form.show = true;
        },
        detail(row) {
            this.detailForm.data = row;
            this.detailForm.show = true;
        },
        onFormSubmit() {
            this.form.show = false;
            this.handleSearch();
        },
        flagChange(data = {}) {
            if (data.delete) {
                this.destroy(data.row);
                return;
            }
            let user = null;
            this.$refs.xTable.tableData.map(v => {
                if (v.playerId === data.index) user = v;
            });
            if (!user) {
                this.$message.error('获取用户信息失败');
                return
            }
            // let user = this.tableData[data.index];
            let updateFunc = (value) => {
                this.$store.dispatch('user/UpdateFlag', Object.assign(data, {userId: user.userId, remark: value})).then(res => {
                    this.$message.success(res.data.message);
                    this.handleSearch();
                });
            }
            if ((user.flagBit & data.flag) === data.flag) {
                updateFunc('');
            } else {
                this.$prompt('请输入备注', '备注一下方便校对', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPlaceholder: '非必填',
                }).then(({value}) => {
                    updateFunc(value);
                });
            }
        },
        flagChangeArr(data = {}) {
            if (!this.selected.length) {
                this.$message.warning('请先选择数据');
                return false;
            }
            let selected = this.selected.filter(v => {
                if(data.index === 'set'){
                    if((v.flagBit & data.flag) === data.flag) {
                        return  false;
                    }
                    return true;
                }else if(data.index === 'cancel'){
                    if(!((v.flagBit & data.flag) === data.flag)) {
                        return  false;
                    }
                    return true;
                }
            });

            if (!selected.length) {
                this.$message.error('选中的条目均不符合处理条件, 无法操作');
                return false;
            }

            let selectedIds = selected.map(v => v.userId);
            console.log(selected);
            let confirmText = selectedIds.length !== this.selected.length ? "选中的条目中, 仅有编号 "+ selected.map(v => v.userId).join(',') + " 可处理, \n是否确认" : "将对选中的数据进行处理\n是否确认";
            this.$prompt(confirmText, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPlaceholder: '请输入备注信息',
                beforeClose: (action, instance, done) => {
                    if (action === 'confirm') {

                        let  value = instance.inputValue
                        instance.confirmButtonLoading = true;
                        instance.confirmButtonText = '执行中...';
                        let failIds = [];
                        // 已选中数据一一处理 防止后端批量处理超时
                        let processEnd = () => {
                            let id = selectedIds.shift();
                            if (!id) {
                                instance.confirmButtonLoading = false;
                                done()
                                this.batchSuccess(failIds);

                                return false;
                            }
                            setTimeout(() => {
                                updateFuncarr(id,value);
                            }, 200);
                        };

                        let updateFuncarr = (id, value) => {
                            this.$store.dispatch('user/UpdateFlag', Object.assign(data, {
                                userId: id,
                                remark: value
                            })).then(res => {
                                // this.$message.success(res.data.message);
                                this.$notify({
                                    title: '提示',
                                    message: res.data.message + ':' + id,
                                    type: 'success'
                                });
                                processEnd();
                            }).catch(error => {
                                failIds.push(id);
                                processEnd();
                            }).finally(() => {

                            });
                        };
                        updateFuncarr(selectedIds.shift(), value);
                    } else {
                        done();
                    }
                }
            }).then(({value}) => {
                console.log(value)
            }).catch(err => {
                console.log(err)
                this.$message.info('取消操作');
            })
        },
        updateSourceOpen() {
            if (!this.selected.length) {
                this.$message.warning('请先选择数据');
                return false;
            }
            this.dialogUpdateSource.success = 0;
            this.dialogUpdateSource.show = true;
        },
        updateSourceSubmit() {
            if (!this.selected.length) {
                this.$message.warning('请先选择数据');
                return false;
            }
            let targetSource = this.dialogUpdateSource.source;
            let remark = this.dialogUpdateSource.remark;
            if (!targetSource) {
                this.$message.warning('请选择目标渠道');
                return false;
            }
            let selected = this.selected.filter(v => v.source !== targetSource);

            if (!selected.length) {
                this.$message.error('选中的条目均不符合处理条件, 无法操作');
                return false;
            }

            let selectedIds = selected.map(v => v.userId);

            let failIds = [];
            // 已选中数据一一处理 防止后端批量处理超时
            let processEnd = () => {
                let id = selectedIds.shift();
                if (!id) {
                    this.batchSuccess(failIds);
                    return false;
                }
                setTimeout(() => {
                    updateFuncarr(id);
                }, 200);
            };

            let updateFuncarr = (id) => {
                this.loading = true;
                this.$store.dispatch('user/Update', {
                    userId: id,
                    source: targetSource,
                    remark: remark,
                }).then(res => {
                    // this.$message.success(res.data.message);
                    this.$notify({
                        title: '提示',
                        message: res.data.message + ':' + id,
                        type: 'success'
                    });
                    processEnd();
                    this.dialogUpdateSource.success += 1;
                }).catch(error => {
                    failIds.push(id);
                    processEnd();
                }).finally(() => {
                    // this.loading = false;
                });
            };
            updateFuncarr(selectedIds.shift());
        },
        // 批量处理完成
        batchSuccess(failIds) {
            if (failIds.length) {

                this.$alert("操作已完成, 编号 "+ failIds.join(',') + ' 处理失败, 请确认', '失败任务提示', {
                    callback: action => {
                        this.handleSearch();
                    }
                });
                return false;
            }
            this.$message.success("操作已全部完成");
            this.handleSearch();
        },
        exportExcel () {
            this.$refs.xTable.exportData({
                filename: '用户列表',
                type: 'xlsx'
            })
        },
        formatUserFlag(flagBit) {
            let text = '';
            if (!flagBit) return text;
            this.$store.state.user.options.flagBit.map(v => {
                if ((flagBit & v.value) === v.value) text += "|"+ v.label;
            });
            return text.substr(1);
        },
        showDialogOperateLogs(userId) {
            this.dialogOperateLog.userId= userId;
            this.dialogOperateLog.show = true;
        },
        showDialogBehaviorLogs(playerId) {
            this.dialogBehaviorLog.playerId= playerId;
            this.dialogBehaviorLog.show = true;
        },
        showDialogBlackList(playerId) {
            this.dialogBlackList.playerId= playerId;
            this.dialogBlackList.show = true;
        },
    },
    created() {
        if (this.$route.query.userId) this.search.userId = this.$route.query.userId;
        if (this.$route.query.playerId) this.search.playerId = this.$route.query.playerId;
        this.initData();

        this.$nextTick(() => {
            this.columnInfos = this.$refs.xTable.getColumns();
        });
    },
}
</script>

<style lang="scss" scoped>
.filter-container .el-form-item{
    margin-bottom: 0 !important;
    .filter-item {
        width: 150px;
    }
}
::v-deep .el-input--mini .el-input__inner {
        height: 30px;
        line-height: 30px;
}
</style>

